﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBControl;
using System.Web.Security;

namespace ProjectX
{
    public partial class ResetPass : Errorbase
    {
        string uname = "";
        string random = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["uname"] == null || Request.QueryString["random"] == null)
                {
                    Response.Redirect("/404.htm");
                }
                else
                {
                    uname = Request.QueryString["uname"];
                    random = Request.QueryString["random"];
                    string getrandom = "SELECT passRandom FROM UserRegister WHERE [userName] = '" + uname + "'";
                    SqlDbHelper sdh = new SqlDbHelper();
                    if (!random.Equals(sdh.ExecuteScalar(getrandom).ToString()))
                    {
                        Response.Redirect("/404.htm");
                    }
                }
            }
        }

        protected void enter_Click(object sender, ImageClickEventArgs e)
        {
            string newpass = FormsAuthentication.HashPasswordForStoringInConfigFile(this.newpass.Text, "MD5");
            string updatepass = "UPDATE UserRegister SET passWord = '" + newpass + "'";
            SqlDbHelper sdh = new SqlDbHelper();
            sdh.ExecuteNonQuery(updatepass);
            this.Panel1.Visible = true;
        }


    }
}